import * as apiService from '@/services/api';

/**
 * 获取入款第三方列表
 * @param {number} channelId 渠道ID
 * @param {number} limitType 额度分类，- 1:不限(默认 )，0:普通 充值商户，1 :大额充值商 户
 * @param {number} status 开关状态(- 1 全部、0-已 开启、1-已 关闭)
 * @param {string} merchantCode 商户号
 * @param {number} page 页码
 * @param {number} size 单页记录条数
 * @returns {*} Promise
 *
 */
export function getRechargeMerchantList({
  channelId,
  limitType,
  status,
  merchantCode,
  page = 1,
  size = 20,
} = {}) {
  return apiService.post('/gl/payment/manage/list/merchant/account', {
    channelId,
    limitType,
    status,
    merchantCode,
    page,
    size,
  });
}

/**
 * 批量开启/关闭商户
 * @param {string} merchantIds 账号ID(数组 ，多个用逗号 隔开)
 * @param {number} status 0-已开启、1-关闭
 * @returns {*} Promise
 *
 */
export function updateRechargeMerchantStatus({
  merchantIds,
  status,
} = {}) {
  return apiService.post('/gl/payment/manage/batch/update/merchant/account', {
    merchantIds,
    status,
  });
}

/**
 * 删除充值渠道账号
 * @param {number} merchantId 账号ID
 * @returns {*} Promise
 *
 */
export function delPaymentEscrow({
  merchantId,
} = {}) {
  return apiService.post('/gl/payment/manage/delete/merchant/account', {
    merchantId,
  });
}

/**
 * 新增第三方入款账号
 * @param {number} channelId 渠道ID
 * @param {number} limitType 额度分类（0：面向普通充值（默认），1：面向大额充值）
 * @param {number} merchantCode 商户号
 * @param {string} publicKey 公钥
 * @param {string} privateKey 私钥
 * @param {string} payUrl 支付地址
 * @param {string} notifyUrl 通知地址
 * @param {string} resultUrl 结果地址
 * @param {string} remark 额度分类备注
 * @param {number} dailyLimit 每日收款上限
 * @returns {*} Promise
 *
 */
export function addPaymentEscrow({
  channelId,
  limitType,
  merchantCode,
  publicKey,
  privateKey,
  payUrl,
  notifyUrl,
  resultUrl,
  remark,
  dailyLimit,
} = {}) {
  return apiService.post('/gl/payment/manage/add/merchant/account', {
    channelId,
    limitType,
    merchantCode,
    publicKey,
    privateKey,
    payUrl,
    notifyUrl,
    resultUrl,
    remark,
    dailyLimit,
  });
}

/**
 * 更新第三方入款账号
 * @param {number} merchantId 账户ID
 * @param {number} channelId 渠道ID
 * @param {number} limitType 额度分类（0：面向普通充值（默认），1：面向大额充值）
 * @param {number} merchantCode 商户号
 * @param {string} publicKey 公钥
 * @param {string} privateKey 私钥
 * @param {string} payUrl 支付地址
 * @param {string} notifyUrl 通知地址
 * @param {string} resultUrl 结果地址
 * @param {string} remark 额度分类备注
 * @param {number} dailyLimit 每日收款上限
 * @returns {*} Promise
 *
 */
export function editPaymentEscrow({
  merchantId,
  channelId,
  limitType,
  merchantCode,
  publicKey,
  privateKey,
  payUrl,
  notifyUrl,
  resultUrl,
  remark,
  dailyLimit,
} = {}) {
  return apiService.post('/gl/payment/manage/update/merchant/account', {
    merchantId,
    channelId,
    limitType,
    merchantCode,
    publicKey,
    privateKey,
    payUrl,
    resultUrl,
    notifyUrl,
    remark,
    dailyLimit,
  });
}

/**
 * 获取出款第三方列表
 * @param {number} channelId 渠道ID
 * @param {number} status 渠道状态(- 1 全部、0-已 开启、1-已 关闭)
 * @param {number} openStatus 开关状态(- 1 全部 、0已开启 、1已关闭)
 * @param {number} page 页码
 * @param {number} size 单页记录条数
 * @returns {*} Promise
 *
 */
export function getWithdrawMerchantList({
  channelId,
  status,
  openStatus,
  page = 1,
  size = 20,
} = {}) {
  return apiService.post('/gl/withdraw/manage/list/merchant/account', {
    channelId,
    status,
    openStatus,
    page,
    size,
  });
}

/**
 * 新增/编辑第三方出款账号
 * @param {number} merchantId 账户ID
 * @param {number} channelId 渠道ID
 * @param {number} merchantCode 商户号
 * @param {string} publicKey 公钥
 * @param {string} privateKey 私钥
 * @param {string} payUrl 支付地址
 * @param {string} notifyUrl 通知地址
 * @param {string} remark 额度分类备注
 * @param {string} minAmount 最小出款金额
 * @param {string} maxAmount 最大出款金额
 * @param {number} dailyLimit 每日收款上限
 * @returns {*} Promise
 *
 */
export function addPaymentWithdraw({
  merchantId,
  channelId,
  merchantCode,
  publicKey,
  privateKey,
  payUrl,
  notifyUrl,
  remark,
  minAmount,
  maxAmount,
  dailyLimit,
} = {}) {
  if (!merchantId) {
    return apiService.post('/gl/withdraw/manage/add/merchant/account', {
      channelId,
      merchantCode,
      publicKey,
      privateKey,
      payUrl,
      notifyUrl,
      remark,
      minAmount,
      maxAmount,
      dailyLimit,
    });
  }
  return apiService.post('/gl/withdraw/manage/update/merchant/account', {
    merchantId,
    channelId,
    merchantCode,
    publicKey,
    privateKey,
    payUrl,
    notifyUrl,
    remark,
    minAmount,
    maxAmount,
    dailyLimit,
  });
}
/**
 * 批量开启/关闭出款商户
 * @param {string} merchantIds 账号ID(数组 ，多个用逗号 隔开)
 * @param {number} status 0-已开启、1-关闭
 * @returns {*} Promise
 *
 */
export function updatePaymentWithdrawOpenStatus({
  merchantIds,
  status,
} = {}) {
  return apiService.post('/gl/withdraw/manage/update/merchant/open', {
    merchantIds,
    status,
  });
}

/**
 * 启用/禁用出款商户账号
 * @param {number} merchantId 账号ID
 * @param {number} status 状态：0启用，1禁用
 * @returns {*} Promise
 *
 */
export function updatePaymentWithdrawStatus({
  merchantId,
  status,
} = {}) {
  return apiService.post('/gl/withdraw/manage/update/merchant/account/status', {
    merchantId,
    status,
  });
}

/**
 * 删除出款渠道账号
 * @param {number} merchantId 账号ID
 * @returns {*} Promise
 *
 */
export function delPaymentWithdraw({
  merchantId,
} = {}) {
  return apiService.post('/gl/withdraw/manage/delete/merchant/account', {
    merchantId,
  });
}

/**
 * 新增/修改银行卡支付
 * @param {number} cardId 银行卡ID
 * @param {number} bankId 银行ID
 * @param {number} limitType 额度类型，0：普通充值（默认），1：大额充值
 * @param {string} bankBranchName 开户支行
 * @param {string} name 开户人姓名
 * @param {string} cardNo 卡号
 * @param {string} qrcode 二维码
 * @param {string} remark 备注
 * @param {number} dailyLimit 每日收款上限
 * @returns {*} Promise
 *
 */
export function addPaymentBank({
  cardId,
  bankId,
  limitType,
  bankBranchName,
  name,
  cardNo,
  qrcode,
  remark,
  dailyLimit,
} = {}) {
  if (!cardId) {
    return apiService.post('/gl/payment/manage/add/bankcard', {
      bankId,
      limitType,
      bankBranchName,
      name,
      cardNo,
      qrcode,
      remark,
      dailyLimit,
    });
  }
  return apiService.post('/gl/payment/manage/update/bankcard', {
    cardId,
    limitType,
    bankId,
    bankBranchName,
    name,
    cardNo,
    qrcode,
    remark,
    dailyLimit,
  });
}
/**
 * 启用/禁用收款卡
 * @param {number} cardId 银行卡ID
 * @param {number} status 状态：0启用，1禁用
 * @returns {*} Promise
 *
 */
export function updatePaymentCardStatus({
  cardId,
  status,
} = {}) {
  return apiService.post('/gl/payment/manage/update/bankcard/status', {
    cardId,
    status,
  });
}
/**
 * 删除收款卡
 * @param {number} cardId 银行卡ID
 * @returns {*} Promise
 *
 */
export function delPaymentCard({
  cardId,
} = {}) {
  return apiService.post('/gl/payment/manage/delete/bankcard', {
    cardId,
  });
}

// 入款配置总览
export const paymentRechargeOverview = params => apiService.post('/gl/payment/manage/level/overview', params);

// 出款配置总览
export const paymentWithdrawOverview = params => apiService.post('/gl/withdraw/manage/withdraw/overview', params);

// 入款配置明细
export const paymentWithdrawDetail = params => apiService.post('/gl/withdraw/manage/withdraw/detail', params);

// 三方账户 查询三方账户的收款统计信息
export const paymentThirdAccountTotalApi = params => apiService.post('/gl/payment/manage/list/merchant/account/total', params);

// 银行账户 查询银行账户的收款统计信息
export const paymentBankcardTotalApi = params => apiService.post('/gl/payment/manage/list/bankcard/total', params);

/**
 * 三方入款应用 列表查询接口
 * @param {array} paymentIds 充值类型(支持多选，逗号隔开;“全部”拼接所有的值)
 * @param {number} channelId 渠道ID
 * @param {string} merchantCode 商户号
 * @param {number} limitType 额度分类，- 1:不限(默认 )，0:普通 充值商户，1 :大额充值商 户
 * @param {string} levelIds 层级类型(支持多选，逗号隔开;“全部”拼接所有的值)
 * @param {number} openStatus 开关状态(- 1 全部 、0已开启 、1已关闭)
 * @param {number} status 渠道状态(- 1 全部、0-已 开启、1-已 关闭)
 * @param {number} clientType 应用端: -1 全部，0 PC端，1 移动端
 * @param {number} recommendStatus 推荐状态:- 1全部、0已推荐、1未推荐
 * @param {number} topStatus 置顶状态:- 1全部、0已置顶、1未置顶
 * @param {number} page 页码
 * @param {number} size 单页记录条数
 * @returns {*} Promise
 *
 */
export function getDepositApplicationList({
  paymentIds,
  channelId,
  merchantCode,
  limitType,
  levelIds,
  openStatus,
  status,
  clientType,
  recommendStatus,
  topStatus,
  page = 1,
  size = 20,
} = {}) {
  return apiService.post('/gl/payment/manage/list/merchant', {
    paymentIds,
    channelId,
    merchantCode,
    limitType,
    levelIds,
    openStatus,
    status,
    clientType,
    recommendStatus,
    topStatus,
    page,
    size,
  });
}

/**
 * 新增/编辑三方支付应用
 * @param {number} id 应用id
 * @param {number} limitType 额度分类，- 1:不限(默认 )，0:普通 充值商户，1 :大额充值商 户
 * @param {string} paymentId 充值类型(支持多选，逗号隔开;“全部”拼接所有的值)
 * @param {number} merchantId 三方商户账号 ID
 * @param {number} clientType 应用端: -1 全部，0 PC端，1 移动端
 * @param {string} levelId 层级类型(支持多选，逗号隔开;“全部”拼接所有的值)
 * @param {string} remark 备注
 * @returns {*} Promise
 *
 */
export function updateDepositApplication({
  id,
  limitType,
  paymentId,
  merchantId,
  clientType,
  levelId,
  remark,
} = {}) {
  if (id) {
    return apiService.post('/gl/payment/manage/update/merchant', {
      id,
      limitType,
      paymentId,
      merchantId,
      clientType,
      levelId,
      remark,
    });
  }
  return apiService.post('/gl/payment/manage/add/merchant', {
    limitType,
    paymentId,
    merchantId,
    clientType,
    levelId,
    remark,
  });
}

/**
 * 置顶/取消置顶三方入款应用
 * @param {number} id 应用id
 * @param {number} topStatus 置顶状态:- 1全部、0已置顶、1未置顶
 * @returns {*} Promise
 *
 */
export function updateDepositApplicationTopping({
  id,
  topStatus,
} = {}) {
  return apiService.post('/gl/payment/manage/update/merchant/topping', {
    id,
    topStatus,
  });
}

/**
 * 获取已经配置商户的充值渠道账号列表的接口
 *  @param {number} limitType 支付类型
 * @returns {*} Promise
 *
 */
export function getDepositAppAccountInuse({
  limitType,
} = {}) {
  return apiService.post('/gl/payment/manage/list/channel', {
    limitType,
  });
}

/**
 * 删除三方入款应用
 * @param {number} id 应用id
 * @returns {*} Promise
 *
 */
export function deleteDepositApplication({
  id,
} = {}) {
  return apiService.post('/gl/payment/manage/delete/merchant', {
    id,
  });
}

/**
 * 启用/禁用三方入款应用
 * @param {number} id 应用id
 * @param {number} status 0启动，1禁用
 * @returns {*} Promise
 *
 */
export function updateDepositApplicationStatus({
  merchantAppIds,
  status,
} = {}) {
  return apiService.post('/gl/payment/manage/update/merchant/status', {
    merchantAppIds,
    status,
  });
}

/**
 * 推荐/取消推荐三方入款应用
 * @param {number} id 应用id
 * @param {number} recommendStatus 推荐状态:- 1全部、0已推荐、1未推荐
 * @returns {*} Promise
 *
 */
export function updateDepositApplicationRecommend({
  id,
  recommendStatus,
} = {}) {
  return apiService.post('/gl/payment/manage/update/merchant/recommend', {
    id,
    recommendStatus,
  });
}

/**
 * 查看已配置层级详情
 * @param {string} levelId 层级id(支持多选，逗号隔开;“全部”拼接所有的值)
 * @returns {*} Promise
 *
 */
export function getWithdrawLevelDetail({
  levelId,
} = {}) {
  return apiService.post('/gl/withdraw/manage/level/list', {
    levelId,
  });
}

/**
 * 查看商户成功率排行
 * @param {number} channelId 支付渠道ID (-1 全部)
 * @param {string} merchantCode 商户号
 * @param {number} page 页码
 * @param {number} size 单页记录条数
 * @returns {*} Promise
 *
 */
export function getMerchantRateList({
  channelId,
  merchantCode,
  page = 1,
  size = 20,
} = {}) {
  return apiService.post('/gl/payment/manage/success/rate/list', {
    channelId,
    merchantCode,
    page,
    size,
  });
}
